package com.neusoft.elmboot.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.neusoft.elmboot.po.DeliveryAddress;
import com.neusoft.elmboot.service.DeliveryAddressService;

@RestController
@RequestMapping("/DeliveryAddresses")
public class DeliveryAddressController {

	@Autowired
	private DeliveryAddressService deliveryAddressService;
	
	@GetMapping("/userId/{userId}")
	public List<DeliveryAddress> listDeliveryAddressByUserId(DeliveryAddress deliveryAddress) throws Exception{
		return deliveryAddressService.listDeliveryAddressByUserId(deliveryAddress.getUserId());
	}
	
	@GetMapping("/daId/{daId}")
	public DeliveryAddress getDeliveryAddressById(DeliveryAddress deliveryAddress) throws Exception{
		return deliveryAddressService.getDeliveryAddressById(deliveryAddress.getDaId());
	} 
	 
	@PostMapping("/contactName/{contactName}/contactSex/{contactSex}/contactTel/{contactTel}/address/{address}/userId/{userId}")
	public int saveDeliveryAddress(DeliveryAddress deliveryAddress) throws Exception{
		return deliveryAddressService.saveDeliveryAddress(deliveryAddress);
	} 
	 
	@PutMapping("/daId/{daId}/contactName/{contactName}/contactSex/{contactSex}/contactTel/{contactTel}/address/{address}/userId/{userId}")
	public int updateDeliveryAddress(DeliveryAddress deliveryAddress) throws Exception{
		return deliveryAddressService.updateDeliveryAddress(deliveryAddress);
	} 
	 
	@DeleteMapping("/daId/{daId}")
	public int removeDeliveryAddress(DeliveryAddress deliveryAddress) throws Exception{
		return deliveryAddressService.removeDeliveryAddress(deliveryAddress.getDaId());
	}
}
